load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

location_f="/Users/ivana/WORK_BSC/AS/files/"

fw    = addfile(location_f + "prect_ano_djf_ipsl.nc", "r")
fc    = addfile(location_f + "prect_ttest90_djf_ipsl.nc", "r")

print(fw)
print(fc)

;*******************************************;
;Read in variables
;*******************************************
lat=fw->LAT
lon=fw->LON

nlat  = dimsizes(lat)
nlon  = dimsizes(lon)

ano=fw->PRECIP_DJF_ANO
prob=fc->SEUIL_PRECIP_DJF

ano = ano*3600*24*30

;-------------------------
; plot
;-------------------------
wks = gsn_open_wks("pdf","prectano_djf_90pctsig_ipsl")

gsn_define_colormap(wks,"BlueDarkOrange18")

plot = new(1,graphic)                          ; create a plot array

  res          = True
  res@gsnDraw  = False                          ; don't draw
  res@gsnFrame = False                          ; don't advance frame, these 2 are going to be set with panel plot - gsn_panel!
  res@cnInfoLabelOn = False                     ; turn off cn info label
  res@cnLinesOn           = False
  res@cnFillOn            = True          ; turn on color
  res@lbLabelBarOn        = True           ; turn off individual cb's
 
  res@mpPerimOn = False
  res@cnLevelSelectionMode =  "ExplicitLevels"

 res@cnLineLabelsOn=False
 res@mpCenterLonF     = 300. 

 res@gsnPolar   = "NH"
 res@mpGeophysicalLineThicknessF = 2.
 res@mpMinLatF            = 30

  res1          = True
  res1@gsnDraw  = False                          ; don't draw
  res1@gsnFrame = False                          ; don't advance frame, these 2 are going to be set with panel plot - gsn_panel!
  res1@cnInfoLabelOn = False                     ; turn off cn info label
  res1@cnLinesOn           = False; True
  res1@cnFillOn            = True          ; turn on color
  res1@lbLabelBarOn        = False           ; turn off individual cb's

  res1@cnMonoFillPattern = False ;True
  res1@cnFillPatterns      = (/-1,8,-1/) ;17, 8, 13
  res1@cnLevelSelectionMode =  "ExplicitLevels"
  res1@cnLevels =(/0.99, 1.01/)  ; ! 90% level

  res1@cnMonoFillColor     = True         ; Use same fill color

  res1@cnFillColor         = (/"black"/)

  res1@cnLineLabelsOn=False
  res1@cnMonoLineColor= True
  res1@cnLineColor      = (/"grey36"/) ; (/"white"/)

  res@lbAutoManage = False
  res@lbLabelFontHeightF  = 0.017
  res@pmLabelBarHeightF  = 0.08

  res1@gsnCenterString = ""
  res1@gsnLeftString = ""
  res1@gsnRightString = ""

  res@gsnLeftString = ""
  res@gsnCenterString = ""
  res@gsnRightString = ""

  res@cnFillColors = (/18,17,16,15,14,13,0,0,11,10,8,5,4,3,2/)
  res@cnLevels =(/-10.,-8,-6,-4,-2,-1,0,1,2,4,6,8, 10/)

  plot(0) = gsn_csm_contour_map(wks,ano(:,:),res)
  plot1 = gsn_csm_contour(wks,gsn_add_cyclic_point(prob),res1)
  overlay(plot(0),plot1)

;________________________
; creating the panel:
;________________________
 resP            = True

resP@gsnPanelLabelBar    = False;True                ; add common colorbar
resP@lbLabelFontHeightF  = 0.007               ; make labels smaller

resP@gsnPanelBottom   = 0.05                   ; add space at bottom
;resP@gsnPanelFigureStrings= (/"a)","b)","c)"/) ; add strings to panel
res@txFontHeightF     = .24


resP@gsnMaximize    = True                ; maximize plot
gsn_panel(wks,plot,(/1,1/),resP)


